/*
 * @file        CCAM_Animation.cpp
 * @version     1.0
 * @author      Johance
 * @email:421465201@qq.com
 * @date        2013-04-24
 * @brief       CCAM_Animation 
 */
#include "CocosPCH.h"

#include "CCAM_AnimationCache.h"
#include "CCAM_AnimationSet.h"
#include "CCAM_AnimationData.h"

static CCAM_AnimationCache *_sharedCCAM_AnimationCache = nullptr;

CCAM_AnimationCache* CCAM_AnimationCache::getInstance()
{
    if (!_sharedCCAM_AnimationCache)
    {
        _sharedCCAM_AnimationCache = new (std::nothrow) CCAM_AnimationCache();
        _sharedCCAM_AnimationCache->init();
    }

    return _sharedCCAM_AnimationCache;
}

void CCAM_AnimationCache::destroyInstance()
{
    CC_SAFE_RELEASE_NULL(_sharedCCAM_AnimationCache);
}

CCAM_AnimationCache::CCAM_AnimationCache()
{

}
CCAM_AnimationCache::~CCAM_AnimationCache(void)
{

}
bool CCAM_AnimationCache::init()
{
    return true;
}

void CCAM_AnimationCache::addAnimationDataWithFile(const std::string& fca)
{
    auto it = m_mapAnimData.find(fca);
    if (it != m_mapAnimData.end())
    {
        return;
    }
    CCAM_AnimationData *pAnimData = CCAM_AnimationData::create();
    pAnimData->LoadFromFile(fca.c_str());
    m_mapAnimData.insert(fca, pAnimData);
}

CCAM_AnimationData *CCAM_AnimationCache::getAnimationData(const std::string& fca)
{
    auto it = m_mapAnimData.find(fca);
    if (it != m_mapAnimData.end())
    {
        return it->second;
    }

    return NULL;
}